from PyQt5.QtWidgets import QApplication

class DebugLog:
    def __init__(self, text_edit):
        self.text_edit = text_edit

    def write(self, message):
        # 确保在主线程中更新 UI
        if hasattr(self.text_edit, 'thread') and self.text_edit.thread() != QApplication.instance().thread():
            self.text_edit.signal_debug_message.emit(message)
        else:
            self.text_edit.append(message)  # 追加到 QTextEdit

    def flush(self):
        pass  # 必须实现，但可以留空
